﻿Imports EstoqueDAL
Public Class ItensInventarioBLL
    Dim objDAL As ItensInventarioDAL

#Region "Propriedades"
    Property inv_codigo As Integer
    Property inv_qtdereal As Integer
    Property pec_codigo As Integer
    Property pec_qtde As Integer
#End Region

#Region "Construtores"
    Sub New()

    End Sub
    Sub New(codigo As Integer, qtde As Integer, peca As Integer, qtdereal As Integer)
        Me.inv_codigo = codigo
        Me.inv_qtdereal = qtdereal
        Me.pec_codigo = peca
        Me.pec_qtde = qtde
    End Sub
#End Region

#Region "Funções"
#Region "Inserir"
    Sub inserir()
        Try
            objDAL = New ItensInventarioDAL
            objDAL.inserir(Me.inv_codigo, Me.inv_qtdereal, Me.pec_codigo, Me.pec_qtde)
        Catch ex As Exception
            Throw ex
        Finally
            objDAL = Nothing
        End Try
    End Sub

#End Region

#Region "Excluir"
    Sub excluir()
        Dim ret As Integer
        Try
            ret = -1
            objDAL = New ItensInventarioDAL
            ret = objDAL.excluirtodositens(Me.inv_codigo)
        Catch ex As Exception
            Throw ex
        Finally
            objDAL = Nothing
        End Try
    End Sub
#End Region

#Region "Localizar"
    Public Function localizar(codigo As String, tipo As Integer) As DataTable
        Try
            objDAL = New ItensInventarioDAL
            Return objDAL.buscar(codigo, tipo)
        Catch ex As Exception
            Throw ex
        End Try
    End Function
#End Region


#Region "Validar"
    Public Function validarcampos() As Boolean
        Dim objpeca As New PECABLL(pec_codigo)
        If (Me.inv_qtdereal <= 0) Then Throw New Exception("Preencha a quantidade real da peça: " & objpeca.pro_descricao)
        Return True
    End Function
#End Region
#End Region

#Region "Procedimentos"
#Region "Limpa Propriedades"
    Sub limpar()
        Me.inv_codigo = Nothing
        Me.inv_qtdereal = Nothing
        Me.pec_qtde = Nothing
        Me.pec_codigo = Nothing
        Me.objDAL = Nothing
    End Sub
#End Region
#End Region
End Class
